/*    */ package com.wzh.utils;
/*    */ 
/*    */ import com.wzh.bean.PageIndex;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ import javax.servlet.http.Cookie;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ 
/*    */ public class WebTool
/*    */ {
/*    */   public static PageIndex getPageIndex(int currentpage, int totalpage)
/*    */   {
/* 16 */     PageIndex pageIndex = new PageIndex();
/* 17 */     if (currentpage - 4 >= 1) {
/* 18 */       pageIndex.setFirstindex(currentpage - 4);
/* 19 */       if (currentpage + 5 > totalpage)
/* 20 */         pageIndex.setLastindex(totalpage);
/*    */       else
/* 22 */         pageIndex.setLastindex(currentpage + 5);
/*    */     }
/*    */     else {
/* 25 */       pageIndex.setFirstindex(1);
/* 26 */       pageIndex.setLastindex(10 > totalpage ? totalpage : 10);
/*    */     }
/* 28 */     return pageIndex;
/*    */   }
/*    */ 
/*    */   public static void addCookie(HttpServletResponse response, String cookiename, String value, int maxAge)
/*    */   {
/* 38 */     Cookie cookie = new Cookie(cookiename, value);
/* 39 */     cookie.setPath("/");
/* 40 */     if (maxAge > 0) {
/* 41 */       cookie.setMaxAge(maxAge);
/*    */     }
/* 43 */     response.addCookie(cookie);
/*    */   }
/*    */ 
/*    */   public static String getCookieByName(HttpServletRequest request, String cookieName)
/*    */   {
/* 52 */     Map cookiemap = readCookieMap(request);
/* 53 */     if (cookiemap.containsKey(cookieName)) {
/* 54 */       return ((Cookie)cookiemap.get(cookieName)).getValue();
/*    */     }
/* 56 */     return null;
/*    */   }
/*    */ 
/*    */   protected static Map<String, Cookie> readCookieMap(HttpServletRequest request)
/*    */   {
/* 61 */     Map cookiemap = new HashMap();
/* 62 */     Cookie[] cookies = request.getCookies();
/* 63 */     if (cookies != null) {
/* 64 */       for (Cookie cookie : cookies) {
/* 65 */         cookiemap.put(cookie.getName(), cookie);
/*    */       }
/*    */     }
/* 68 */     return cookiemap;
/*    */   }
/*    */ 
/*    */   public static boolean isMHost(HttpServletRequest request)
/*    */   {
/* 77 */     boolean result = false;
/*    */ 
/* 79 */     String host = request.getServerName();
/* 80 */     if ((host != null) && (host.startsWith("m."))) {
/* 81 */       result = true;
/*    */     }
/*    */ 
/* 85 */     return result;
/*    */   }
/*    */ }

/* Location:           C:\work\apache-tomcat-7.0.55\webapps\ROOT\WEB-INF\classes\
 * Qualified Name:     com.wzh.utils.WebTool
 * JD-Core Version:    0.6.1
 */